<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="入户服务记录" :showOkBtn="false" :showCancelBtn="false">
    <a-select v-model:value="selectedOption" style="width: 100%;" @change="handleSelectChange">
      <a-select-option value="before">入户前</a-select-option>
      <a-select-option value="during">入户中</a-select-option>
      <a-select-option value="after">入户后</a-select-option>
    </a-select>
    <BeforeVisitService
      v-if="selectedOption === 'before'"
      :orderId="orderId"
    />
    <OnServiceRecord
      v-if="selectedOption === 'during'"
      :orderId="orderId"
    />
    <AfterVisitService
      v-if="selectedOption === 'after'"
      :orderId="orderId"
    />
  </BasicModal>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import BeforeVisitService from './VisitServiceRecordModalPage/BeforeVisitService.vue';
import AfterVisitService from './VisitServiceRecordModalPage/AfterVisitService.vue';
import OnServiceRecord from './VisitServiceRecordModalPage/OnServiceRecord.vue';

const selectedOption = ref('before');

const orderId = ref<string | undefined>(undefined);

// 注册modal，设置宽度为780px，高度为400px
const [registerModal, { setModalProps, closeModal }] = useModalInner((data) => {

  console.log('Received data:', data);

  // 在每次模态框打开时将订单号赋值给orderId
  if (data.record) {
    orderId.value = data.record.code;
    console.log('Received orderId:', orderId.value);
  }

  // 重置表单
  selectedOption.value = 'before';
  
  // 设置modal属性，宽度为600px，高度为400px，隐藏底部按钮
  setModalProps({
    width: 700,
    bodyStyle: {
      height: '500px'
    },
    showOkBtn: false,
    showCancelBtn: false
  });
});

const handleSelectChange = (value) => {
  console.log('选择的选项值:', value);
  // 在这里可以处理选中的选项值
  // 例如发送请求或更新状态等
};

// 如果需要在选择后自动关闭模态框，可以在这里处理
// const handleSelectChange = (value) => {
//   console.log('选择的选项值:', value);
//   // 处理选中的选项值后自动关闭模态框
//   setTimeout(() => {
//     closeModal();
//   }, 1000);
// };

defineExpose({
  // 不需要额外暴露方法，useModalInner已经处理了
});
</script>
